package matrixCalculator;

import java.util.Vector;

import Jama.Matrix;

public class MatrixBuffer {
	private Matrix work;
	private Vector<Matrix> works;

	private boolean bufferEmtpy = true;
	
	public MatrixBuffer(){
		this.works = new Vector<Matrix>();
	}

	public synchronized void putWork(Matrix msg){
		while(!bufferEmtpy){
			try{
				wait();
			}catch(InterruptedException i){
				System.out.println("interrupted");
			}

		}
		works.add(msg);
		bufferEmtpy = false;
		notifyAll();
	}

	public synchronized Matrix getWork(){
		while(bufferEmtpy){
			try{
				wait();				
			}catch(InterruptedException i){
				System.out.println("interrupted");
			}

		}
		work = works.lastElement();
		bufferEmtpy = true;

		notifyAll();
		return work;
	}
}
